package com.hgw.easyrocketmq.filter;

import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;
import org.apache.rocketmq.remoting.exception.RemotingException;

import java.io.UnsupportedEncodingException;

/**
 * Description: 属性过滤生产者
 *
 * @author LinHuiBa-YanAn
 * @date 2023/2/14 14:49
 */
public class FilterProducer {

    public static void main(String[] args) throws MQClientException, RemotingException, InterruptedException, MQBrokerException, UnsupportedEncodingException {
        DefaultMQProducer mqProducer = new DefaultMQProducer("group1");
        mqProducer.setNamesrvAddr("47.96.232.192:9876");
        mqProducer.start();
        for (int i = 1; i <= 10; i++) {
            Message msg = new Message("FilterTest", "tag", ("Hello RocketMQ " + i).getBytes(RemotingHelper.DEFAULT_CHARSET));
            // 设置一些属性
            msg.putUserProperty("a", String.valueOf(i));
            mqProducer.send(msg);
        }
        mqProducer.shutdown();
    }

}
